import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:study_demo/ui/pick_color/pick_color_controller.dart';

class PickColorPage extends StatelessWidget {
  ui.Color? pickedColor;

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PickColorController>(
        init: PickColorController(),
        builder: (controller) {
          return Scaffold(
              appBar: AppBar(
                title: Text('取色器'),
              ),
              body: RepaintBoundary(
                key: repaintKey,
                child: GestureDetector(
                    onTapDown: (details) {
                      _onTapDown(details, controller, context);
                    },
                    child: Container(
                      child: Column(
                        children: [
                          Expanded(child: Container(color: Colors.green)),
                          Expanded(child: Container(color: Colors.redAccent)),
                          Expanded(child: Container(color: Colors.yellow)),
                          Expanded(child: Container(color: Colors.blueAccent)),
                          Expanded(
                              child: Container(color: Colors.deepPurpleAccent))
                        ],
                      ),
                    )),
              ));
        });
  }

  void _onTapDown(TapDownDetails details, PickColorController controller,
      BuildContext context) async {
    final color =
        await controller.getPixelColor(context, details.globalPosition);
    print('color:$color');
  }
}
